<%@page import="java.util.Calendar"%>
<%@page import="org.jsoup.Jsoup"%>
<%@page import="model.SubCategoryModel"%>
<%@page import="entity.Category"%>
<%@page import="model.CategoryModel"%>
<%@page import="model.TagModel"%>
<%@page import="model.NewsModel"%>
<%@page import="entity.News"%>
<%@page import="entity.Tag"%>
<%@page import="java.util.List"%>
<%@page import="util.ResourceHelper"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
	  request.setCharacterEncoding("UTF-8");
 	  SubCategoryModel subModel = new SubCategoryModel();    
	  CategoryModel cateModel = new CategoryModel();
	  NewsModel newsModel = new NewsModel();
	  TagModel tagModel = new TagModel();
      News detail = null;      
      if(request.getAttribute("detail")!=null){                
    	  detail = (News)request.getAttribute("detail");                                    
      }
      String title = detail.getTitle() + " - " +ResourceHelper.getByAlias("luu-tru-tin");
      String description = detail.getTitle();
      String keywords = detail.getTitle();
      for(String key : detail.getTagged()){
    	  keywords += ", " + tagModel.findByAlias(key).getTitle();
    	  keywords += ", " + key.replaceAll("-", " ");
      }
      Calendar cal = Calendar.getInstance();
      cal.setTime(detail.getDoc());
      String day = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR) ;
      String dateLink = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) ;
  %>
<jsp:include page="/layout/header.jsp">	
	<jsp:param name="cate" value="<%= detail.getCategory() %>"/>
	<jsp:param name="title" value="<%=title %>"/>	
	<jsp:param name="keywords" value="<%= keywords%>"/>
	<jsp:param name="description" value="<%=description %>"/> 
</jsp:include>
        <div id="content">
        	<div id="leftsidecontent">
            	<div class="box-wrap">
                	<div class="box-categories">                        
                        <div class="clearbreak"></div>                        
                    </div>
                    <div class="box-item news-detail" itemscope itemtype="http://schema.org/Article">
                        <div class="box-item_inner">                        	
                            <h1 class="heading" itemprop="headline"><%=detail.getTitle()%></h1>
                            <div class="news-content">
                                <h3 class="heading">
                                    <a href="/<%=detail.getCategory() %>"><%=cateModel.findByAlias(detail.getCategory()).getTitle() %></a>&nbsp;
                                    <a href="/<%=detail.getCategory() %>/<%=detail.getSubCategory()%>"><%=subModel.findByAlias(detail.getSubCategory()).getTitle() %></a>&nbsp; 
                                    <a href="/<%=dateLink%>">(<%= day%>)</a>
                                </h3>
                                <div style="font-weight: bold">
                                	 <%= detail.getDescription().replaceAll("<img[^>]+>", "")%>                                                                      
                                </div>                                
                                <div>
                                    <%
                                        if(detail.getRelateUrls()!=null&&detail.getRelateUrls().size()>0){
                                            for(String relateLink: detail.getRelateUrls()){
                                                News relate = newsModel.findRelatedLink(relateLink);
                                                if(relate!=null&&relate.getContent()!=null){                                                                                                
                                                %>
                                                <p><a href="/<%=relate.getAlias() %>.html">>> <%= relate.getTitle() %></a></p>
                                                <%
                                                }
                                            }
                                        }                                        
                                    %>
                                </div>
                                <br />
                                <div itemprop="articleBody" class="articlebody">
                                    <%=detail.getContent() %>
                                </div>
                                <div style="font-weight: bold; float: right">
                                    <p itemprop="author"><%
                                    	if(detail.getAuthor()!=null){
                                    		%>
                                    			<%= detail.getAuthor() %> 
                                    		<%
                                    	}
                                    %></p>
                                    <p style="color: #CA0000;">(<%=ResourceHelper.getByAlias("nguon") %> : <%=detail.getSourceName() %>)</p>
                                </div>
                                <div class="addthis">
				                 	 <!-- AddThis Button BEGIN -->
				                     <div class="addthis_toolbox addthis_default_style ">
				                     <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
				                     <a class="addthis_button_tweet"></a>
				                     <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
				                     <a class="addthis_counter addthis_pill_style"></a>
				                     </div>
				                     <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4d6f3cdb1d190d60"></script>
				                     <!-- AddThis Button END -->
				                </div>
                                <div class="clearbreak"></div>
                            </div>                           
                            <%                           	 	
                            	Tag item;
                            	if(detail.getOtherTags()!=null&& detail.getOtherTags().size()>0){
                            		%>
                            			<div class="tag">
			                            	<%=ResourceHelper.getByAlias("tu-khoa-khac") %> : 
			                                 <%			                                    			                            		
			                                    for(String tag: detail.getOtherTags()){
			                                    	item = tagModel.findByAlias(tag);
			                                    	if(item.getTitle()!=null&&!item.getTitle().equalsIgnoreCase("")){
				                                   	%>
			                                    		<a href="/tag/<%= tag%>" itemprop="keywords"><%= tagModel.findByAlias(tag).getTitle() %></a>
				                                    <%}
			                                    }
			                                %>                                   	                               
			                                <div class="clearbreak"></div>
			                            </div>
                            		<%
                            	}
                            %>
                            
                        </div>
                    </div>
                   <jsp:include page="/element/relate_news.jsp">	
                        	<jsp:param name="alias" value="<%=detail.getAlias() %>"/>	
					</jsp:include>
                </div>
            </div>
            <div id="rightsidecontent">
            	<div class="box-wrap">
                	 <jsp:include page="/element/search.jsp">	
                        	<jsp:param name="cate" value="<%=detail.getCategory() %>"/>	
					</jsp:include>
                   	 <jsp:include page="/element/tagged.jsp">    
                    	<jsp:param name="id" value="<%=detail.getId()%>"/>	                   	
					 </jsp:include>
                     <jsp:include page="/element/latest_news.jsp">	
                       	<jsp:param name="cate" value="<%=detail.getCategory()%>"/>	
					 </jsp:include>
                      <jsp:include page="/element/another_news.jsp">
                       	<jsp:param name="cate" value="<%=detail.getCategory()%>"/>		
					 </jsp:include>                    
                    <div class="clearbreak"></div>               
                </div>
            </div>
            <div class="clearbreak"></div>
        </div>
<jsp:include page="/layout/footer.jsp">	
	<jsp:param name="cate" value="<%=detail.getCategory() %>"/>	
</jsp:include>